package cn.iocoder.yudao.module.vos.service.gatewaylevel;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vos.controller.admin.gatewaylevel.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.gatewaylevel.GatewayLevelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vos.dal.mysql.gatewaylevel.GatewayLevelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vos.enums.ErrorCodeConstants.*;

/**
 * 网关等级 Service 实现类
 *
 * @author shijun
 */
@Service
@Validated
public class GatewayLevelServiceImpl implements GatewayLevelService {

    @Resource
    private GatewayLevelMapper gatewayLevelMapper;

    @Override
    public Long createGatewayLevel(GatewayLevelSaveReqVO createReqVO) {
        // 插入
        GatewayLevelDO gatewayLevel = BeanUtils.toBean(createReqVO, GatewayLevelDO.class);
        gatewayLevelMapper.insert(gatewayLevel);

        // 返回
        return gatewayLevel.getId();
    }

    @Override
    public void updateGatewayLevel(GatewayLevelSaveReqVO updateReqVO) {
        // 校验存在
        validateGatewayLevelExists(updateReqVO.getId());
        // 更新
        GatewayLevelDO updateObj = BeanUtils.toBean(updateReqVO, GatewayLevelDO.class);
        gatewayLevelMapper.updateById(updateObj);
    }

    @Override
    public void deleteGatewayLevel(Long id) {
        // 校验存在
        validateGatewayLevelExists(id);
        // 删除
        gatewayLevelMapper.deleteById(id);
    }

    @Override
        public void deleteGatewayLevelListByIds(List<Long> ids) {
        // 删除
        gatewayLevelMapper.deleteByIds(ids);
        }


    private void validateGatewayLevelExists(Long id) {
        if (gatewayLevelMapper.selectById(id) == null) {
            throw exception(GATEWAY_LEVEL_NOT_EXISTS);
        }
    }

    @Override
    public GatewayLevelDO getGatewayLevel(Long id) {
        return gatewayLevelMapper.selectById(id);
    }

    @Override
    public PageResult<GatewayLevelDO> getGatewayLevelPage(GatewayLevelPageReqVO pageReqVO) {
        return gatewayLevelMapper.selectPage(pageReqVO);
    }

}